<template>
  <!--卡种详情页-->
  <div>
    <p class="title">{{goods.goodsName}}
      <span @click="goIndex()">跳过 <img :src="src" alt="" height="10"></span></p>
    <p class="imgid"><img :src="goods.coverImg | imgPathFilter" alt="" width="100%"></p>
    <ul class="introduce">
      <div v-html="goods.goodsDesc"></div>
    </ul>
    <div class="xieyi">
      <a @click="toggle">
        <img src="../../../assets/cheakbox.png" alt="" width="20" v-show="isAgree">
        <img src="../../../assets/radio.png" alt="" width="20" v-show="!isAgree"><span @click="goLook(goods.goodsId)">阅读并同意</span>
      </a>
      <wv-button type="default" :plain="true" @click="goBuy(goods.goodsId)">立即购买</wv-button>
    </div>

  </div>
</template>

<script type="text/ecmascript-6">
  import {getVipcardDetail} from '../../../../test/unit/http'
  import {wxApi} from '../../../../test/unit/flyme_weixin'
  import global from '../../../../test/unit/global'

  import {Toast} from 'we-vue'

  export default {
    name: 'jinkadetail',
    props: {},
    data() {
      return {
        src: require('../../../assets/arrow.png'),
        banner: require('../../../assets/jinkabanner.png'),
        isAgree: false,
        goods: {}
      };
    },
    methods: {
      goLook(goodsId) {
        if (this.goods.isNeedSign == 1) {
          //需要签名,直接跳到带有签名的协议页
          this.$router.push({
            path: '/jinkaxieyisign',
            query: {goodsId: goodsId, showType: true}
          });
        } else {
          //不需要签名
          this.$router.push({
            path: '/jinkaxieyi',
            query: {goodsId: goodsId, showType: true}
          });
        }

      },
      toggle() {
        this.isAgree = !this.isAgree
      },
      goIndex() {
        this.$router.push({path: 'index'})
      },
      goBuy(goodsId) {
        if (this.goods.isNeedSign == 1) {
          //需要签名,直接跳到带有签名的协议页
          this.$router.push({
            path: '/jinkaxieyisign',
            query: {goodsId: goodsId, showType: true}
          });
        } else {
          if (!this.isAgree) {
            Toast.text('请确认阅读并同意');
            return;
          }
          //不需要签名
          let enterType = this.$route.query.enterType;
          let params = {goodsId: goodsId};
          if (!this.$myUtils.isNull(enterType)) {
            params['enterType'] = enterType;
          }
          this.$router.push({path: 'submitorder', query: params})
        }

      },
      getVipcardDetailData(params) {
        getVipcardDetail(params).then(res => {
          console.log(res);
          if (res.code == 100) {
            this.goods = res.object;
          } else {
            Toast.fail(res.info);
          }
        })
      }
    },
    created() {
      let goodsId = this.$route.query.goodsId;
      this.getVipcardDetailData({goodsId: goodsId});
      let url = window.location.href;
      let shareUrl = this.$myUtils.initShareUrl(url);
      let that = this;
      wxApi.init(function () {
        wxApi.updateAppMessageShareData(that.goods.goodsName, that.goods.goodsName, shareUrl, global.ImgBaseURL + '/' + that.goods.coverImg)
      });
    },
    components: {}
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  .title {
    color: #dabe5e;
    font-size: 20px;
    padding: 10px;
    text-align: left;

    span {
      float: right;
      color: rgba(255, 255, 255, 0.5);
      background-color: rgba(0, 0, 0, 0.2);
      padding: 3px 7px;
      border-radius: 5px;
      font-size: 12px;

      img {
        vertical-align: middle;
        margin-bottom: 2px;
      }
    }
  }

  .imgid {
    position: relative;

    span {
      position: absolute;
      top: 37px;
      right: 28px;
      color: #7b4813;
      font-weight: 700;
    }
  }

  .introduce {
    padding: 10px 10px 70px;
    text-align: left;

    li:first-child {
      font-size: 20px;
      color: #111;
      font-weight: 700;
    }

    li:last-child {
      color: #666;
      font-size: 15px;
      line-height: 25px;
      text-indent: 30px;
    }
  }

  .xieyi {
    background-color: #fff;
    position: fixed;
    bottom: 0px;
    width: 100%;
    display: flex;
    padding: 10px;
    align-items: center;

    a {
      img {
        vertical-align: middle;
        margin-right: 5px;
      }

      color: #2f95f0;
      font-size: 14px;
    }

    button {
      background-color: #ff8551;
      color: #fff;
      height: 40px;
      line-height: 40px;
      border-radius: 25px;
      border: none;
      width: 160px;
      margin-right: 25px;

    }
  }
</style>
